package org.imaginedays.androidall.ui;

import org.imaginedays.androidall.R;
import org.imaginedays.androidall.app.AndroidAllApp;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

/**
 * 检查机器root与否，如果root 看是否授予权限，如果没有弹出对话框提示。
 * 
 * @author imaginedays
 * 
 */
public class CheckDeviceRootACT extends Activity implements OnClickListener {

	protected String TAG = "CheckDeviceRootACT";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.check_device_root);

		findViewById(R.id.btn_check_device_root).setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		if (!AndroidAllApp.getInstance().coreTask.hasRootPermission()){
			openNotRootDialog();
		}else{
			Toast.makeText(this, "该机器已经被root", Toast.LENGTH_SHORT).show();
		}
		
		
	}

	private void openNotRootDialog() {
		LayoutInflater li = LayoutInflater.from(this);
		View view = li.inflate(R.layout.norootview, null);
		new AlertDialog.Builder(CheckDeviceRootACT.this)
				.setTitle(getString(R.string.main_activity_notroot))
				.setView(view)
				.setMessage(R.string.noroot_msg)
				.setNegativeButton(getString(R.string.main_activity_exit),
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								CheckDeviceRootACT.this.finish();
							}
						})
				.setNeutralButton(getString(R.string.main_activity_ignore),
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								// CheckDeviceRootACT.this.application.installFiles();
								// CheckDeviceRootACT.this.application.displayToastMessage("Ignoring, note that this application will NOT work correctly.");
							}
						}).show();
	}

}
